package com.lovo.controller;

import com.lovo.bean.StudentBean;
import com.lovo.result.ResponseResult;
import com.lovo.service.IStudentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

@RestController
@RequestMapping("/students")
@Api(value = "学生控制器")
public class StudentController {
    @Resource
    private IStudentService studentService;
    @GetMapping("/{id}")
    @ApiOperation(value = "根据Id查询学生",notes = "根据Id查询学生，Id必须存在，否则报错")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "学生id",required = true,dataType = "Long",paramType = "path",defaultValue = "1")
    })
    public Object showById(@PathVariable("id") Long id){
        return studentService.selectById(id);
    }
    @PostMapping
    @ResponseResult
    public Object add(@RequestBody @Valid StudentBean studentBean){
        studentService.add(studentBean);
        return "成功123";
    }
}
